package com.cwd.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.cwd.dao.MemberDao;
import com.cwd.dao.OrderDao;
import com.cwd.utils.DateUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackageName: com.cwd.service
 * @ClassName: ReportServiceImpl
 * @Author: CWD
 * @Date: 2020/3/15 17:32
 * @Description:
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    //运营数据统计分析
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //报表日期，显示的是当前的时间
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //查询本日新增会员
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //查询总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //查询本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //查询本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        
        //查询今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //查询今日到诊人数
       Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
       //查询本周预约人数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        //查询本周到诊人数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        //查询本月预约人数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        //查询本月到诊人数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        //查询热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String,Object> map = new HashMap<>();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",todayOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
